﻿using vowei.web.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Web.Mvc;
using Vowei.Data.Helpers;
using System.Linq;
using Vowei.Data;

namespace vowei.test
{
    [TestClass()]
    public class RoleControllerTest : TestBase
    {
        [TestMethod()]
        public void MatchUserEmailTest()
        {
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin_shi@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin.shi@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("v-yishi@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin_shi@hotmail.com.cn"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin.shi@hotmail.net"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("v-yishi@hotmail.org"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin.shi123@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin.123@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("yimin23@hotmail.com"));
            Assert.IsTrue(EntityHelpers.MatchUserEmail("v-yishi@hotmail.com.cn.cn"));

            Assert.IsFalse(EntityHelpers.MatchUserEmail("v-yishi@hotmail"));
            Assert.IsFalse(EntityHelpers.MatchUserEmail("v-yishi@"));
            Assert.IsFalse(EntityHelpers.MatchUserEmail("@hotmail.com"));
        }

        [TestMethod()]
        [HostType("ASP.NET")]
        [AspNetDevelopmentServerHost("C:\\vowei\\src\\vowei.web", "/")]
        [UrlToTest("http://localhost:2011/Role/Create")]
        public void CreateRoleBasicTest()
        {
            var target = new RoleController(VoweiContext);
            var collection = new FormCollection();

            using (var context = new VoweiContextImpl())
            {
                collection["PermissionSet"] = context.PermissionSet.First().ID.ToString("D");
            }

            collection["RoleName"] = string.Format("EditTest_Role_{0}", Guid.NewGuid());
            ActionResult actual = target.Edit(collection);
            Assert.IsTrue(actual is RedirectResult);
        }
    }
}
